package com.briup.oagg.model.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.briup.framework.utils.web.Response;
import com.briup.oagg.model.bean.ext.ModelTrainConfigExt;
import com.briup.oagg.model.constants.MockData;
import com.briup.oagg.model.service.IModelTrainConfigService;
import com.briup.oagg.model.web.vm.ModelTrainConfigAddVM;
import com.briup.oagg.model.web.vm.ModelTrainConfigVM;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 模型训练配置前端控制器
 *
 * @author briup
 */
@Api(tags = "5.模型训练配置信息管理")
@RestController
@RequestMapping("/train")
public class ModelTrainConfigController {
    @Autowired
    private IModelTrainConfigService service;

    @ApiOperation(value = "多条件查询训练配置信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "modelType",value = "模型类型",allowableValues = "classification,cluster,regression",dataTypeClass = String.class),
            @ApiImplicitParam(name = "modelId",value = "模型编号",dataTypeClass = String.class)
    })
    @GetMapping
    public Response<List<ModelTrainConfigVM>> findByCondition(String modelType,String modelId){
        List<ModelTrainConfigVM> list = service.findByCondition(modelType,modelId);
        return Response.success(list);
    }

    @ApiOperation(value = "根据训练编号查询指定模型训练配置信息")
    @GetMapping("/{trainId}")
    public Response<ModelTrainConfigVM> findByTrainId(@PathVariable String trainId){
        ModelTrainConfigVM vm = service.findByTrainId(trainId);
        return Response.success(vm);
    }

    @ApiOperation(value = "新建模型训练",notes = MockData.data)
    @ApiImplicitParam(name = "vm",value = "新建模型训练配置参数")
    @PostMapping
    public Response<String> addModelTrain(@RequestBody ModelTrainConfigAddVM vm){
        service.addModelTrain(vm);
        return Response.success();
    }

    @ApiOperation(value = "开启模型训练")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "trainId",value = "训练编号",paramType = "path"),
            @ApiImplicitParam(name = "dataList",value = "数据集数据",paramType = "body")
    })
    @PostMapping(value = "/{trainId}")
    public Response<String> beginTrain(@PathVariable String trainId,
                                          @RequestBody List<Map<String,Object>> dataList){
        service.beginTrain(trainId,dataList);
        return Response.success();
    }

    @ApiOperation(value = "修改模型训练状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "trainId",value = "训练编号",dataTypeClass = String.class),
            @ApiImplicitParam(name = "publishStatus",value = "训练状态：0 未发布 1 已发布",allowableValues = "0,1",dataTypeClass = Integer.class)
    })
    @PutMapping
    public Response<String> updatePublishStatus(@RequestParam String trainId,
                                                @RequestParam Integer publishStatus){
        service.updatePublishStatus(trainId,publishStatus);
        return Response.success();
    }

    @ApiOperation(value = "根据训练编号删除指定模型训练配置信息")
    @ApiImplicitParam(name = "trainId",value = "训练编号",paramType = "path",dataTypeClass = String.class)
    @DeleteMapping("/{trainId}")
    public Response<String> deleteByTrainId(@PathVariable String trainId){
        service.deleteByTrainId(trainId);
        return Response.success();
    }
}
